package com.wangshuile.netty.ch1;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	private static final String HOST="127.0.0.1";
	
	private static final int PORT=8000;
	
	private static final int SLEEP_TIME=5000;
	
	public static void main(String[] args) throws UnknownHostException, IOException {
		final Socket socket=new Socket(HOST,PORT);
		new Thread(new Runnable() {
			@Override
			public void run() {
				
				System.out.println("客户端启动成功!");
				while(true) {
					try{
						OutputStream out=socket.getOutputStream();
						String message="hello world!";
						System.out.println("客户端发生数据:"+message);
						out.write(message.getBytes());
					} catch (IOException e) {
						System.out.println("写数据出错!");
					}
					sleep();
				}
			}
		}).start();
	}

	protected static void sleep() {
		try {
			Thread.sleep(SLEEP_TIME);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
